package chapter2.observerMode.observable.impl;

import chapter2.observerMode.observable.Observable;
import chapter2.observerMode.observer.Observer;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ClockObservable implements Observable {
    Set<Observer> observers;

    public ClockObservable(){
        observers = new HashSet<>();
    }

    @Override
    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        observers.stream().forEach((observer) -> {observer.update(LocalDateTime.now());});
    }
}
